import { Component, Node, _decorator } from "cc";
import { CustomEventListener } from "../data/CustomEventListener";
import { E2LProtocol, L2EProtocol } from "../proto/ELProtocol";
import { Login } from "./Login";
const { ccclass, property } = _decorator;

@ccclass("UIManager")
export class UIManager extends Component{
    @property({
        type: Node,
    })
    welcomeLayer: Node = null;

    @property({
        type: Node,
    })
    updateLayer: Node = null;
    
    @property({
        type: Login
    })
    login: Login | null = null;
    
    onLoad() {
        CustomEventListener.on(E2LProtocol.e2l_welcome_over, this.welcomeOver, this);
        CustomEventListener.on(L2EProtocol.l2e_show_login, this.showLogin, this);
    }
    
    onDestroy() {
        CustomEventListener.off(E2LProtocol.e2l_welcome_over, this.welcomeOver, this);
        CustomEventListener.off(L2EProtocol.l2e_show_login, this.showLogin, this);

    }

    update() {

    }

    private welcomeOver() {
        this.welcomeLayer.active = false;
        this.login.node.active = true;
        CustomEventListener.dispatchEvent(E2LProtocol.e2l_start_login);
    }

    private showLogin() {
        this.login.node.active = true;
        this.login.showLoginButton();
    }
}


